+2005-07-22 Matthias Clasen <mclasen@redhat.com>
+
+ * gdk-pixbuf/tmpl/module_interface.sgml: Document unanchored
+ patterns.
+
2005-07-21 Federico Mena Quintero <federico@ximian.com>
* gtk/tmpl/gtkfilechooserdialog.sgml (dialog): Expand the Save
<!-- ##### STRUCT GdkPixbufModulePattern ##### -->
<para>
The signature of a module is a set of prefixes. Prefixes are encoded as
-pairs of ordinary strings, where the second string, if not %NULL, must be
-of the same length as the first one and may contain ' ', '!', 'x', 'z',
-and 'n' to indicate bytes that must be matched, not matched,
-"don't-care"-bytes, zeros and non-zeros.
+pairs of ordinary strings, where the second string, called the mask, if
+not %NULL, must be of the same length as the first one and may contain
+' ', '!', 'x', 'z', and 'n' to indicate bytes that must be matched,
+not matched, "don't-care"-bytes, zeros and non-zeros.
Each prefix has an associated integer that describes the relevance of
the prefix, with 0 meaning a mismatch and 100 a "perfect match".
</para>
-
+<para>
+Starting with &gdk-pixbuf; 2.8, the first byte of the mask may be '*',
+indicating an unanchored pattern that matches not only at the beginning,
+but also in the middle. Versions prior to 2.8 will interpret the '*'
+like an 'x'.
+</para>
<para>
The signature of a module is stored as an array of
#GdkPixbufModulePattern<!-- -->s. The array is terminated by a pattern
+2005-07-22 Matthias Clasen <mclasen@redhat.com>
+
+ * gdk-pixbuf-io.c (format_check): Interpret patterns where
+ the first byte of the mask is '*' as unanchored. (#311011)
+ (gdk_pixbuf_new_from_file): Use the first 256 bytes for
+ sniffing the file format.
+
2005-07-15 Matthias Clasen <mclasen@redhat.com>
* === Released 2.7.3 ===
static gint
format_check (GdkPixbufModule *module, guchar *buffer, int size)
{
- int j;
+ int i, j;
gchar m;
GdkPixbufModulePattern *pattern;
+ gboolean unanchored;
+ guchar *prefix, *mask;
for (pattern = module->info->signature; pattern->prefix; pattern++) {
- for (j = 0; j < size && pattern->prefix[j] != 0; j++) {
- m = pattern->mask ? pattern->mask[j] : ' ';
- if (m == ' ') {
- if (buffer[j] != pattern->prefix[j])
- break;
- }
- else if (m == '!') {
- if (buffer[j] == pattern->prefix[j])
- break;
- }
- else if (m == 'z') {
- if (buffer[j] != 0)
- break;
- }
- else if (m == 'n') {
- if (buffer[j] == 0)
- break;
- }
- }
- if (pattern->prefix[j] == 0)
- return pattern->relevance;
+ if (pattern->mask && pattern->mask[0] == '*') {
+ prefix = pattern->prefix + 1;
+ mask = pattern->mask + 1;
+ unanchored = TRUE;
+ }
+ else {
+ prefix = pattern->prefix;
+ mask = pattern->mask;
+ unanchored = FALSE;
+ }
+ for (i = 0; unanchored && i < size; i++) {
+ for (j = 0; i + j < size && prefix[j] != 0; j++) {
+ m = mask ? mask[j] : ' ';
+ if (m == ' ') {
+ if (buffer[i + j] != prefix[j])
+ break;
+ }
+ else if (m == '!') {
+ if (buffer[i + j] == prefix[j])
+ break;
+ }
+ else if (m == 'z') {
+ if (buffer[i + j] != 0)
+ break;
+ }
+ else if (m == 'n') {
+ if (buffer[i + j] == 0)
+ break;
+ }
+ }
+ if (prefix[j] == 0)
+ return pattern->relevance;
+ }
}
return 0;
}
GdkPixbuf *pixbuf;
int size;
FILE *f;
- guchar buffer [128];
+ guchar buffer[256];
GdkPixbufModule *image_module;
gchar *display_name;